package mvp.hibernate.demo.controller;

import mvp.hibernate.demo.dao.PhoneDao;
import mvp.hibernate.demo.model.Phone;
import mvp.hibernate.demo.model.PhoneType;

import java.util.Iterator;
import java.util.List;

/**
 * Created by user on 06.07.14.
 */
public class PhoneManager {
    private PhoneDao phoneDao;

    public PhoneManager() {
        phoneDao = new PhoneDao();
    }

    public void createSomePhones() {
        phoneDao.savePhone(new Phone("123", PhoneType.HOME));
        phoneDao.savePhone(new Phone("46382334", PhoneType.HOME));
        phoneDao.savePhone(new Phone("2342355", PhoneType.WORK));
        phoneDao.savePhone(new Phone("878727832", PhoneType.WORK));
    }

    public void printPhones() {
        List<Phone> all = phoneDao.getAllPhones();
        Iterator<Phone> iter = all.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.next().toString());
        }
    }

    public void concModification() {
        Phone phone = phoneDao.getPhoneById(2L);
        phone.setNumber("7890_changed");
        phoneDao.updatePhone(phone);
        phone.setNumber("35443_chnaged2");
        phoneDao.updatePhone(phone);
    }
}
